package main

type PlayerMgr struct {
	playerMap map[string]*Player
}

func NewPlayerMgr() *PlayerMgr {
	playerMgr := PlayerMgr{}
	playerMgr.playerMap = make(map[string]*Player)
	return &playerMgr
}

func (pm *PlayerMgr) AddPlayer(player *Player) {
	pm.playerMap[player.Name] = player
}

func (pm *PlayerMgr) RemovePlayer(name string) {
	delete(pm.playerMap, name)
}

func (pm *PlayerMgr) GetPlayers() *map[string]*Player {
	return &pm.playerMap
}

func (pm *PlayerMgr) FindPlayer(name string) *Player {
	return pm.playerMap[name]
}

func (pm *PlayerMgr) updatePlayerName(oldName string, newName string) {
	player := pm.FindPlayer(oldName)
	if player != nil {
		player.Name = newName
		pm.playerMap[newName] = player
		pm.RemovePlayer(oldName)
	}
}
